<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改文章')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" /> 
    <link rel="stylesheet" href="/colorpicker/bootstrap-colorpicker.css"/>
    <th:block th:include="include :: select2-css" />
    
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-article-edit" th:object="${cmsArticle}">
        
        <div class="row">
            
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label is-required">栏目：</label>
                <div class="col-sm-8">
                    <div class="input-group"  onclick="selectArticlecategoryTree()">
                        <input id="treeId" name="categoryId" type="hidden" th:field="*{categoryId}" required/>
                        <input class="form-control" type="text"  id="treeName" readonly="true" th:field="*{categoryName}" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>            
            <div class="form-group  col-sm-6">    
                <label class="col-sm-4 control-label">推荐位：</label>
                <div class="col-sm-8">
                    <select name="dictPostPositions" class="form-control m-b" th:with="type=${@dict.getType('dict_post_positions')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictPostPositions}"></option>
                    </select>
                </div>
            </div>            

        
            
        </div>     
        
         <div class="row">
            <div class="form-group col-sm-12">    
                <label class="col-sm-2 control-label is-required">标题：</label>
                <div class="col-sm-10">
								<div class="input-group">
									<input name="title" th:field="*{title}" class="form-control " type="text" required />
									<span class="input-group-btn">
										 <span class="input-group input-color " data-color-format="hex">
											<span class="input-group-addon" style="border-radius:0;border-left:0;">
												<i style="background-color:#343036"></i>
											</span>
											<input name="color" style="width:80px;"  placeholder="标题颜色" th:field="*{color}" class="form-control" type="text">
										</span>
									</span>
								</div>

                </div>
            </div>            

           
        </div>    
    
 	<div class="row">         
            <div class="form-group  col-sm-6">
                <label class="col-sm-4 control-label"><span class="help-block m-b-none"><i class="fa fa-info-circle" title="请用逗号分割标签"></i> 标签：</span> </label>
                <div class="col-sm-8">
                   <input name="tags" th:field="*{tags}" type="hidden" required>
                   <select class="js-example-tags form-control" id="tagsselect" name="tagsselect"  required> 
                   
  				   </select>
                   
                </div>
            </div>
           <div class="form-group  col-sm-6">    
                <label class="col-sm-4 control-label">内容视图：</label>
                <div class="col-sm-8">
                    <select name="dictContentView" class="form-control m-b" th:with="type=${@dict.getType('dict_content_view')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictContentView}"></option>
                    </select>
                </div>
            </div>         
  </div>           
        
        
        <div class="row">  
            <div class="form-group col-sm-12">
                <label class="col-sm-2 control-label">外部链接：</label>
                <div class="col-sm-10">
               		<input name="href" type="url" class="form-control" th:field="*{href}"  />
                </div>
            </div>
        </div>    
		<div class="row">        
            <div class="form-group  col-sm-12">
                <label class="col-sm-2 control-label">关键字：</label>
                <div class="col-sm-10">
                    <textarea name="keywords" class="form-control" required>[[*{keywords}]]</textarea>
                </div>
            </div>
		</div>      
		
		<div class="row">        
            <div class="form-group  col-sm-12">
                <label class="col-sm-2 control-label">描述：</label>
                <div class="col-sm-10">
                   <textarea name="description" class="form-control" required>[[*{description}]]</textarea>
                </div>
            </div>
		</div>     		
		     
  
        
        
         <div class="row">        
        
            <div class="form-group  col-sm-6">    
                <label class="col-sm-4 control-label">展示策略：</label>
                <div class="col-sm-8">
                    <select name="dictShowStrategy" class="form-control m-b" th:with="type=${@dict.getType('dict_show_strategy')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictShowStrategy}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group   col-sm-6">    
                <label class="col-sm-4 control-label">会员策略：</label>
                <div class="col-sm-8">
                    <select name="dictVipStrategy" class="form-control m-b" th:with="type=${@dict.getType('dict_vip_strategy')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictVipStrategy}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group   col-sm-6">    
                <label class="col-sm-4 control-label">是否允许套餐：</label>
                <div class="col-sm-8">
                    <select name="dictIsPackage" class="form-control m-b" th:with="type=${@dict.getType('dict_is_package')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictIsPackage}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group   col-sm-6">    
                <label class="col-sm-4 control-label">是否允许优惠券：</label>
                <div class="col-sm-8">
                    <select name="dictIsCoupon" class="form-control m-b" th:with="type=${@dict.getType('dict_is_coupon')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{dictIsCoupon}"></option>
                    </select>
                </div>
            </div>
            
		</div>            
       <div class="row ">               
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label">市场价：</label>
                <div class="col-sm-8 input-group m-b">
                    <input name="maxPrice"  th:field="*{maxPrice}" class="form-control number" type="text" required> <span class="input-group-addon">元</span>
                </div>
            </div>
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label">销售价：</label>
                <div class="col-sm-8 input-group m-b">
                    <input name="price"    th:field="*{price}" class="form-control number" type="text" required> <span class="input-group-addon">元</span>
                </div>
            </div>
            
      </div>             
        <div class="row ">               
            
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label">销售数量：</label>
                <div class="col-sm-8">
                    <input name="saleNumber" th:field="*{saleNumber}" class="form-control number" type="text" required>
                </div>
            </div>
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label">点击数：</label>
                <div class="col-sm-8">
                    <input name="hits" th:field="*{hits}" class="form-control number" type="text" required>
                </div>
            </div>
            <div class="form-group col-sm-6">    
                <label class="col-sm-4 control-label">收藏数：</label>
                <div class="col-sm-8">
                    <input name="collectionCount" th:field="*{collectionCount}" class="form-control number" type="text" required>
                </div>
            </div>    
            
            <div class="form-group  col-sm-6">    
                <label class="col-sm-4 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control number" type="text" required>
                </div>
            </div>            
                    
      </div>      



		 <div class="row">              
            
            
            <div class="form-group  col-sm-12">    
                <label class="col-sm-2 control-label">封面：</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control "  name="image" th:field="*{image}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="image" name="file" type="file">
                    </div>
                </div>
            </div>




			</div>
		 <div class="row">              

            <div class="form-group">    
                <label class="col-sm-2 control-label">内容：</label>
                <div class="col-sm-10">
                   <input th:field="*{cmsArticleData.content}" type="hidden">
                   <div id="editor" class="summernote"></div>
                </div>
            </div>
         </div>   
            
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />    
    <script src="/colorpicker/bootstrap-colorpicker.js"></script>
    <th:block th:include="include :: select2-js" />
	<script type="text/javascript">
	var selectTags='[[${cmsArticle.tags}]]'.split(',');
	var selectTagsData=[];
	$.each(selectTags,function(index,value){
		selectTagsData.push({id: value, text: value});
	});
		
	
	$("#tagsselect").select2({
		tokenSeparators: [',', ' '], 
		placeholder:'请您录入标签然后回车',
		tags: true,
		data: selectTagsData,
		theme: "bootstrap",
	    multiple: true, 
	});
	
	
	$('#tagsselect').val(selectTags).trigger("change"); // 多个赋值
	
	</script>   
    <script th:inline="javascript">
 // 颜色控件初始化
    $("#form-article-edit .input-color").colorpicker();
        var prefix = ctx + "ecms/article";
        $("#form-article-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
        	
        	var sHTML = $('.summernote').summernote('code');
        	$("#cmsArticleData\\.content").val(sHTML);
        	$('#tags').val($('#tagsselect').select2('val'));
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-article-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                allowedFileTypes: ['image'],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
        

    </script>
    <script type="text/javascript">
    /*文章分类-编辑-选择父文章分类树*/
    function selectArticlecategoryTree() {
        var options = {
            title: '文章分类选择',
            width: "380",
            url: ctx + "ecms/articlecategory" + "/selectArticlecategoryTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
    	
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }   
    

    $(function() {
	    $('.summernote').summernote({
	    	placeholder: '请输入公告内容',
	    	height : 192,
			lang : 'zh-CN',
			followingToolbar: false,
			dialogsInBody: true,
			callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
	    });
		var content = $("#cmsArticleData\\.content").val();
	    $('#editor').summernote('code', content);
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
			dialogsInBody: true,
			height: 300,               //编辑器高度
	        minHeight: 300,             // 最小高度
	        maxHeight: 1500,             // 最大高度
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                	$(obj).summernote('editor.insertImage', result.url, result.fileName);
				} else {
					$.modal.alertError(result.msg);
				}
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }
   
	 
    </script>    
</body>
</html>